//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.basic.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao;
import net.mingsoft.basic.biz.IManagerBiz;
import net.mingsoft.basic.dao.IManagerDao;
import net.mingsoft.basic.dao.IRoleDao;
import net.mingsoft.basic.entity.ManagerEntity;
import net.mingsoft.basic.entity.RoleEntity;
import net.mingsoft.basic.util.SpringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("managerBiz")
@Transactional
public class ManagerBizImpl extends BaseBizImpl<IManagerDao, ManagerEntity> implements IManagerBiz {
    private IManagerDao managerDao;

    public ManagerBizImpl() {
    }

    public IManagerDao getManagerDao() {
        return this.managerDao;
    }

    @Autowired
    public void setManagerDao(IManagerDao managerDao) {
        this.managerDao = managerDao;
    }

    public IBaseDao getDao() {
        return this.managerDao;
    }

    public void updateUserPasswordByUserName(ManagerEntity manager) {
        this.managerDao.updateUserPasswordByUserName(manager);
    }

    public List<ManagerEntity> queryAllChildManager(int managerId) {
        return this.managerDao.queryAllChildManager(managerId);
    }

    public List<ManagerEntity> queryAllManager(List<ManagerEntity> managerList) {
        IRoleDao roleDao = (IRoleDao)SpringUtil.getBean(IRoleDao.class);
        List<RoleEntity> roleList = roleDao.selectList(new QueryWrapper());
        Iterator var4 = managerList.iterator();

        while(var4.hasNext()) {
            ManagerEntity manager = (ManagerEntity)var4.next();
            StringBuilder roleNames = new StringBuilder();
            String[] roleIds = manager.getRoleIds().split(",");
            List<String> allRoleName = new ArrayList();
            String[] var9 = roleIds;
            int var10 = roleIds.length;

            for(int var11 = 0; var11 < var10; ++var11) {
                String roleId = var9[var11];
                List<String> roleNameList = (List)roleList.stream().filter((roleEntity) -> {
                    return roleEntity.getId().equals(roleId);
                }).map(RoleEntity::getRoleName).collect(Collectors.toList());
                allRoleName.addAll(roleNameList);
            }

            roleNames.append(StringUtils.join(allRoleName, ","));
            manager.setRoleName(roleNames.toString());
        }

        return managerList;
    }

    public ManagerEntity getManagerByManagerName(String managerName) {
        ManagerEntity managerEntity = new ManagerEntity();
        managerEntity.setManagerName(managerName);
        return (ManagerEntity)this.managerDao.getByEntity(managerEntity);
    }
}
